//
//  MainTabBarController.swift
//  XingCeHelper
//
//  Created by 申铭 on 2022/12/6.
//

import UIKit

class MainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let tabBar = UITabBar.appearance()
        let appearance = UITabBarAppearance()
        
        tabBar.tintColor = .label
        tabBar.standardAppearance = appearance

        addChildVC(childVC: PracticeCollectionViewController(), childTitle: "练习", imageName: "tabbar_arithmetic_icon", selectedImageName: "tabbar_arithmetic_selected_icon")
        addChildVC(childVC: TimerTableViewController(), childTitle: "计时器", imageName: "tabbar_timer_icon", selectedImageName: "tabbar_timer_selected_icon")
        addChildVC(childVC: StatisticsViewController(), childTitle: "统计", imageName: "tabbar_statistics_icon", selectedImageName: "tabbar_statistics_selected_icon")
    }
    
    
    @discardableResult
    private func addChildVC(childVC: UIViewController, childTitle: String, imageName:String, selectedImageName:String, needNav: Bool = true) -> UIViewController {
        let navigation = BaseNavigationController(rootViewController: childVC)
        navigation.navigationBar.tintColor = .label
        childVC.navigationItem.title = childTitle
        childVC.tabBarItem.title = childTitle
        childVC.tabBarItem.image = UIImage(named: imageName)?.withRenderingMode(.alwaysOriginal)
        childVC.tabBarItem.selectedImage = UIImage(named: selectedImageName)?.withRenderingMode(.alwaysOriginal)

        if needNav {
            addChild(navigation)
        } else {
            addChild(childVC)
        }

        return childVC
    }

}
